from pydantic import BaseModel, Field
from typing import Optional, List, Dict
from datetime import datetime


class InstagramMediaFormatInfo(BaseModel):
    """Instagram媒体格式信息DTO"""
    format_id: str = Field(..., description="格式ID")
    ext: str = Field(..., description="文件扩展名")
    resolution: str = Field(..., description="分辨率")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    url: Optional[str] = Field(None, description="下载链接")
    quality: Optional[float] = Field(None, description="质量分数")
    format_note: Optional[str] = Field(None, description="格式说明")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")


class InstagramMediaInfo(BaseModel):
    """Instagram媒体信息DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    like_count: Optional[int] = Field(None, description="点赞数")
    comment_count: Optional[int] = Field(None, description="评论数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    is_video: bool = Field(..., description="是否为视频")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    formats: List[InstagramMediaFormatInfo] = Field(default_factory=list, description="可用格式列表")


class InstagramInfoResponse(BaseModel):
    """获取Instagram媒体信息响应DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    like_count: Optional[int] = Field(None, description="点赞数")
    comment_count: Optional[int] = Field(None, description="评论数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    is_video: bool = Field(..., description="是否为视频")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    formats: List[InstagramMediaFormatInfo] = Field(default_factory=list, description="可用格式列表")


class InstagramDownloadUrlInfo(BaseModel):
    """Instagram下载链接信息DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="文件格式")
    resolution: str = Field(..., description="分辨率")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    is_video: bool = Field(..., description="是否为视频")


class InstagramDownloadUrlResponse(BaseModel):
    """获取Instagram下载链接响应DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="文件格式")
    resolution: str = Field(..., description="分辨率")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    is_video: bool = Field(..., description="是否为视频")


class InstagramQualityUrlInfo(BaseModel):
    """Instagram质量下载链接信息DTO"""
    url: str = Field(..., description="下载链接")
    format: str = Field(..., description="文件格式")
    width: Optional[int] = Field(None, description="宽度")
    height: Optional[int] = Field(None, description="高度")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")


class InstagramMultiQualityInfo(BaseModel):
    """Instagram多质量下载信息DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    quality_urls: Dict[str, InstagramQualityUrlInfo] = Field(..., description="不同质量的下载链接")
    available_qualities: List[str] = Field(..., description="可用的质量选项")
    is_video: bool = Field(..., description="是否为视频")


class InstagramMultiQualityResponse(BaseModel):
    """获取Instagram多质量下载链接响应DTO"""
    media_id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="媒体标题/描述")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    quality_urls: Dict[str, InstagramQualityUrlInfo] = Field(..., description="不同质量的下载链接")
    available_qualities: List[str] = Field(..., description="可用的质量选项")
    is_video: bool = Field(..., description="是否为视频")


class InstagramUserMediaItem(BaseModel):
    """Instagram用户媒体项DTO"""
    id: str = Field(..., description="媒体ID")
    title: str = Field(..., description="标题")
    url: str = Field(..., description="媒体链接")
    thumbnail: Optional[str] = Field(None, description="缩略图")
    duration: Optional[float] = Field(None, description="时长")
    view_count: Optional[int] = Field(None, description="观看次数")


class InstagramUserMediaInfo(BaseModel):
    """Instagram用户媒体信息DTO"""
    username: str = Field(..., description="用户名")
    user_id: Optional[str] = Field(None, description="用户ID")
    user_title: Optional[str] = Field(None, description="用户显示名")
    media_count: int = Field(..., description="获取到的媒体数量")
    media_list: List[InstagramUserMediaItem] = Field(..., description="媒体列表")


class InstagramUserMediaResponse(BaseModel):
    """获取Instagram用户媒体响应DTO"""
    username: str = Field(..., description="用户名")
    user_id: Optional[str] = Field(None, description="用户ID")
    user_title: Optional[str] = Field(None, description="用户显示名")
    media_count: int = Field(..., description="获取到的媒体数量")
    media_list: List[InstagramUserMediaItem] = Field(..., description="媒体列表")


class InstagramSupportedQualitiesResponse(BaseModel):
    """Instagram支持的质量选项响应DTO"""
    qualities: List[str] = Field(..., description="支持的质量选项")
    default_quality: str = Field(..., description="默认质量")
    description: str = Field(..., description="说明")
    
    
class InstagramUrlTypesResponse(BaseModel):
    """Instagram支持的URL类型响应DTO"""
    url_types: List[Dict[str, str]] = Field(..., description="支持的URL类型")
    examples: Dict[str, str] = Field(..., description="URL示例")
    description: str = Field(..., description="说明") 